import socket
import sys

class Pipe(object):
    def __init__(self,ip,port):
        self.ip = ip
        self.port = port
        
    def startConnection(self,host,port):
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.bind((host,port))
        s.listen(1)
        self.conn, addr = s.accept()
        print "connected to client @", addr
        
        
    def recvData(self):
        data = self.conn.recv(1024)
        if not data: return None
        self.conn.send(data)
        print data
        return data
        
    def closeConnection(self):
        self.conn.close()

    def requestData(self, item):
        self.conn.send(item)    
        
if __name__ == "__main__":
    ip = ""
    port = 1234
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    pipe = Pipe(ip,port)
    pipe.startConnection(ip,port)
    pipe.recvData()
    pipe.requestData('testing')
    pipe.closeConnection()
    #data = conn.recvData()
    #print item
    
    
